@page "/ai/requestrecord"
@using BootBlazor.Servers.Auth
@using BootBlazor.Servers.Components.Pages
@using BootBlazor.Servers.Helper
@using BootBlazor.Servers.Data
@using BootBlazor.Servers.Services

@rendermode RenderMode.InteractiveServer
@attribute [StreamRendering]

<PageHeader Title="@Loc["AIRequestRecord_Title"]">
    <MudGrid Spacing="2" Class="justify-end">
        <MudItem xs="12" sm="6" md="3" lg="2" xl="1">
            <MudDatePicker Label="@Loc["AIRequestRecord_SearchStartTime"]" @bind-Date="searchObject.StartTime"
                           DateFormat="yyyy-MM-dd" Variant="Variant.Outlined" Margin="Margin.Dense"
                           Class="search-com" />
        </MudItem>
        <MudItem xs="12" sm="6" md="3" lg="2" xl="1">
            <MudDatePicker Label="@Loc["AIRequestRecord_SearchEndTime"]" @bind-Date="searchObject.EndTime"
                           DateFormat="yyyy-MM-dd" Variant="Variant.Outlined" Margin="Margin.Dense"
                           Class="search-com" />
        </MudItem>
        <MudItem xs="12" sm="6" md="3" lg="2" xl="1">
            <MudTextField Label="@Loc["AIRequestRecord_SearchConfigCode"]" @bind-Value="searchObject.AiConfigCode"
                          Variant="Variant.Outlined" Margin="Margin.Dense" Class="search-com" />
        </MudItem>
        <MudItem>
            <MudIconButton Size="MudBlazor.Size.Medium" Icon="@Icons.Material.Filled.Search" OnClick="() => { dataGrid.ReloadServerData(); }"
                           Variant="Variant.Outlined" Color="Color.Primary" Class="mr-2">
            </MudIconButton>
            <MudTooltip Text="@Loc["Button_ResetSearch"]" Color="Color.Primary">
                <MudIconButton Size="MudBlazor.Size.Medium" Icon="@Icons.Material.Filled.SearchOff" OnClick="SearchReset"
                               Variant="Variant.Outlined" Color="Color.Primary" Class="mr-2">
                </MudIconButton>
            </MudTooltip>
        </MudItem>
    </MudGrid>
</PageHeader>

<MudDataGrid Dense=PageDataGridConfig.Dense Filterable=PageDataGridConfig.Filterable ColumnResizeMode=PageDataGridConfig.ColumnResizeMode
             SortMode=PageDataGridConfig.SortMode Groupable=PageDataGridConfig.Groupable Virtualize=PageDataGridConfig.Virtualize
             FixedHeader=PageDataGridConfig.FixedHeader Elevation=PageDataGridConfig.Elevation Outlined=PageDataGridConfig.Outlined
             Style="@PageDataGridConfig.Style" HorizontalScrollbar="PageDataGridConfig.HorizontalScrollbar"
             ServerData="GetTableData" @ref="dataGrid" T="RequestRecordModel">
    <Columns>
        <PropertyColumn Property="x => x.Number" Title="@Loc["AIRequestRecord_TableH1"]" StickyLeft="true" Resizable="false" HeaderStyle="white-space:nowrap;width:60px;" />
        <PropertyColumn Property="x => x.ConfigName" Title="@Loc["AIRequestRecord_TableH7"]" HeaderStyle="white-space:nowrap" />
        <PropertyColumn Property="x => x.ElapsedMilliseconds" Title="@Loc["AIRequestRecord_TableH8"]" HeaderStyle="white-space:nowrap" />
        <PropertyColumn Property="x => x.RequestTime" Title="@Loc["AIRequestRecord_TableH2"]" HeaderStyle="white-space:nowrap" />
        <PropertyColumn Property="x => x.RequestTokens" Title="@Loc["AIRequestRecord_TableH3"]" HeaderStyle="white-space:nowrap" />
        <PropertyColumn Property="x => x.ResponseTokens" Title="@Loc["AIRequestRecord_TableH4"]" HeaderStyle="white-space:nowrap" />
        <PropertyColumn Property="x => x.TotalPrice" Title="@Loc["AIRequestRecord_TableH5"]" HeaderStyle="white-space:nowrap" />
        <TemplateColumn Title="@Loc["AIRequestRecord_TableH6"]" HeaderStyle="white-space:nowrap;width:50px;min-width:50px;" StickyRight="true" Resizable="false">
            <CellTemplate>
                <MudIconButton Size="@MudBlazor.Size.Small" Icon="@Icons.Material.Outlined.Details" Color="Color.Primary"
                               OnClick="() => ShowDetail(context.Item.Id)" />
            </CellTemplate>
        </TemplateColumn>
    </Columns>
</MudDataGrid>

<PagePagination PageInfo="searchObject" PageChangedClick="PageChangedClick"></PagePagination>
